<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>axios常用配置以及默认配置</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.3.6/axios.js"></script>
</head>

<body>
    <button>王者荣耀</button>
    <button>英雄联盟</button>
    <button>段子</button>
    <button>xxx</button>
    <script>
        /**
         * method  设置请求方法
         * url     设置 url
         * params  设置查询字符串
         * headers 设置请求头
         * data    设置请求体
         * baseURL 设置基础的 URL
         */

        let btns = document.querySelectorAll('button');
        //设置 axios 的配置的默认值   (了解即可)
        axios.defaults.baseURL = 'http://api.xiaohigh.com';
        axios.defaults.headers.token = 'aewafewafewaefeawf';
        // console.log(axios.defaults);
        axios.defaults.params = {};
        axios.defaults.params.q = '战士';

        btns[0].onclick = async function () {
            let result = await axios.get('/heros');
            console.log(result);
        }

        btns[1].onclick = async function () {
            let result = await axios.get('/lol');
            console.log(result);
        }

        btns[2].onclick = async function () {
            let result = await axios.get('/duanzi');
            console.log(result);
        }

        btns[3].onclick = async function () {
            let result = await axios.get('http://localhost:3000/song');
            console.log(result);
        }
    </script>
</body>

</html>